<?php
class MTeam extends CI_Model{

	public function __construct()
    {
        parent::__construct();
    }
	function getTeam($id) {
		$data = array();
	    $this->db->where('TeamID',id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get('team');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;      
	}
	
	function getTeamDropdown()
	{
		 $data = array();
		 $this->db->where('TeamActive',1);
		 $this->db->order_by("TeamName", "ASC");
	     $Q = $this->db->get('team');
	     if ($Q->num_rows() > 0){
	       $data[0] = '...select team...';
	       foreach ($Q->result_array() as $row){
	         $data[$row['TeamID']] = $row['TeamName'];
	       }
	     }
	     $Q->free_result();    
	     return $data; 	
	}
	
	function getAllTeams(){
	     $data = array();
	     $this->db->order_by("TeamName", "ASC");
	     $Q = $this->db->get('team');
	     if ($Q->num_rows() > 0){
	       foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
	     }
	     $Q->free_result();    
	     return $data; 	
	}
	
	function addTeam()
	{
		$data = array( 
			'TeamName' => db_clean($_POST['TeamName']),
			'Comment' => db_clean($_POST['Comment']),
			'TeamActive' => db_clean(isset($_POST['TeamActive']) ? 1 : 0 )
		);
		$this->db->set('CreatedDate', 'NOW()', FALSE);
		$this->db->insert('team', $data);	 
	}
	
	function updateTeam()
	{
		$data = array( 
			'TeamName' => db_clean($_POST['TeamName']),
			'Comment' => db_clean($_POST['Comment']),
			'TeamActive' => db_clean(isset($_POST['TeamActive']) ? 1 : 0 )
		);
		$this->db->set('ModifiedDate', 'NOW()', FALSE);
	    $this->db->where('TeamID',id_clean($_POST['TeamID']));
		$this->db->update('team', $data);	
	}
}
?>